package com.exartisan.thanhdoanhn;

import com.exartisan.util.FbUtil;
import com.facebook.Session;
import com.facebook.SessionState;
import com.facebook.Session.StatusCallback;
import com.loopj.android.image.SmartImageView;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.TextView;

public class EventDetailActivity extends BaseActivity {
	
	private TextView tvName;
	private TextView tvDesc;
	private TextView tvStartDay;
	private TextView tvEndDay;
	private SmartImageView imgCover;

	@Override
	protected void setUpActionBar() {
		super.setUpActionBar();
		getSupportActionBar().setDisplayShowHomeEnabled(false);
		getSupportActionBar().setDisplayShowTitleEnabled(false);
		getSupportActionBar().setDisplayShowCustomEnabled(true);
		getSupportActionBar().setCustomView(R.layout.ab_list);
	}

	@Override
	protected void initUI() {
		setContentView(R.layout.activity_event_detail);
		tvName = (TextView) findViewById(R.id.tvName);
		tvDesc = (TextView) findViewById(R.id.tvDesc);
		tvStartDay = (TextView) findViewById(R.id.tvTimeStart);
		tvEndDay = (TextView) findViewById(R.id.tvTimeEnd);
		imgCover = (SmartImageView) findViewById(R.id.imgCover);
	}

	@Override
	protected void initProcess() {
		tvName.setText(event.getEventName());
		tvDesc.setText(event.getDescription());
		tvStartDay.setText(event.getStartDate());
		tvEndDay.setText(event.getEndDate());
		imgCover.setImageUrl(event.getThumbUrl());
	}
	
	public void onClickBack(View v){
		finish();
	}
	
	public void onClickShare(View v){
		Session session = Session.getActiveSession();
		if(session==null||session.isClosed()) Session.openActiveSession(getActivity(), true, new StatusCallback() {
			
			@Override
			public void call(Session session, SessionState state, Exception exception) {
				if(session != null){
					if(state.isOpened()){
						FbUtil.ShareToFb(getActivity(), event.getEventName(), event.getDescription(), FbUtil.YN_LINK, event.getThumbUrl());
					}
				}
			}
		}); else
			FbUtil.ShareToFb(getActivity(), event.getEventName(), event.getDescription(), FbUtil.YN_LINK, event.getThumbUrl());
	}
	
	public void onClickGallery(View v){
		Intent i = new Intent(this, GalleryActivity.class);
		startActivity(i);
	}
	
	public void onClickJoin(View v){
		PackageManager pm = getPackageManager();
		Intent i = pm.getLaunchIntentForPackage("com.exartisan.molisasurvey");
		startActivity(i);
	}

}
